package com.mcy.springbatch.job;

import com.mcy.springbatch.entity.SysUser;
import com.mcy.springbatch.job.BaseJobConfig;
import com.mcy.springbatch.processer.ParamItemProcessor;
import com.mcy.springbatch.writer.SysUserItemWriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.*;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;

import java.util.Map;

/**
 * Job的参数Demo
 */
@Slf4j
@Configuration
public class GJobParamJobConfig extends BaseJobConfig {

    @Autowired
    private ParamItemProcessor paramItemProcessor;

    @Autowired
    private ListItemReader<SysUser> userDataListItemReader;

    @Autowired
    private SysUserItemWriter sysUserItemWriter;

    @Bean(name = "paramJob")
    public Job paramJob() {
        return jobBuilderFactory.get("paramJob")
                .incrementer(new RunIdIncrementer())
                .start(paramJobStep())
                .build();
    }

    @Bean
    public Step paramJobStep() {
        return stepBuilderFactory.get("paramJobStep")
                .<SysUser,SysUser>chunk(10)
                .reader(userDataListItemReader)
                .processor(paramItemProcessor)
                .writer(sysUserItemWriter)
                .build();

    }

}
